<template>
	<view class="content">
		<view class="custom-page-box">
			<view class="search-box">
				<uni-search-bar :radius="100" @confirm="search" v-model="keyword"></uni-search-bar>
			</view>
			<view class="custom-list">
				<view class="custom-top">
					<image src="../../static/progress.png" mode="widthFix"></image>
				</view>
			</view>
			<view class="custom-list-p">
				<text>特别提示: 单点米饭请与食材一起下单，谢谢！</text>
			</view>
			<view class="menu-wrapper-box">
				<scroll-view class="menu-wrapper" scroll-y :scroll-top="left_scroll" scroll-with-animation="true" :style="'height:'+windows_height+'px'">
					<view class="left-content">  <!-- 一级类 -->
						<view style="position: relative;" v-for="(item,index) in yijilei" :key="index" ref="menuList"
							@click="select(index,item.id)" :class="yijileiIndex == index?'current':''">
							<view class="menu-item">{{item.name}}</view>
						</view>
					</view>
				</scroll-view>

				<view class="foods-wrapper" :style="'height:'+windows_height+'px'">
					<view ref="foodsWrapper">
						<view ref="foodList" class="foods" :style="'height:'+windows_height+'px'">
							<view class="foods-btou" :class="{ active: isActive }">
								<!-- <text style="display: none;">{{item.children.name}}</text> -->
								<text :class="childrenIndex == -1?'active':''" @click="childrenCk(-1)">全部</text>
								<text :class="childrenIndex == c?'active':''" v-for="(children, c) in goods1.children"
									:key="c" @click="childrenCk(c)">{{children.title}}</text>
							</view>
							<!-- <view v-for="(food, f) in item.foods" :key="f"> -->
							<scroll-view class="foods-box" :class="{ active: isActive }" scroll-y 
					:scroll-top="foodSTop" @scroll="myscroll" scroll-with-animation="true" :style="'height:'+(windows_height- 60)+'px'">
								<view v-for="(item, i) in goods1.foods" :key="i">
									<view class="food-title">
										{{item.name}}
									</view>
									<view class="food" v-if="item.list.length == 0">
										<view class="food-info"
											style="height: 20px;text-align: center;width: 100%;color:#999;">
											暂无菜品</view>
									</view>
									<view class="food" v-else v-for="(list, l) in item.list" :key="l">
										<view class="food-info-img" style="border-radius: 10px;">
											<image :src="list.cover" mode="aspectFill" @click="details(list.id)"></image>
										</view>
										<view class="food-info"
											style="display: inline-block;height: 65px;vertical-align: top;">
											<text
												style="font-size: 14px; margin: 2upx auto 4upx;">{{list.title}}</text>
											<text
												style="font-size: 12px;margin: 2px auto; color: #999;display:block;">月售{{list.sales}}</text>
											<view class="food-btm">
												<text
													class="food-price"><text>￥{{list.attrs[0].discount_price}}</text><text>￥{{list.attrs[0].market_price}}</text></text>
												<button type="default" class="xhg-btn" v-if="list.attrs.length>1"
													@click="guigeCk(list)">选规格</button>
												<button type="default" class="xhg-btn" v-else
													@click="addCart(list)">+</button>
											</view>
										</view>
									</view>
								</view>
							</scroll-view>
						</view>
					</view>
				</view>
				<view class="pesong-sj">
					<text class="pesong-sj-txt">今天23点前下单，最早明天 11：30开始配送</text>
				</view>
				<view class="goods-nav">
					<view class="cart-btn-box">
						<view class="iconBox-ico" @tap="showBanner">
							<text class="cart-btn-bt">{{num}}</text>
						</view>
						<view class="cart-btn-tetx">
							<text class="cart-cie">￥{{zongqian}}</text>
							<text>已优惠{{youhui}}元</text>
						</view>
					</view>
					<view class="btn-box">
						<button type="default" class="bot-btn" @click="xybck(item)">下一步</button>
						<!-- <button type="default" class="bot-btn2" @click="zhifu">支付</button> -->
					</view>
				</view>
			</view>
		</view>
		<view class="zbc" v-if="zbc">
			<view class="xiuxi" v-if="xiuxi">{{msg}}</view>
			<view class="yuedu-tc" v-if="show">
				<button class="qx-btn" @click="queding">×</button>
				<view class="yuedu-tc-box">
					<view class="yuedu-tc-bt">定制点餐说明</view>
					<view class="yuedu-tc-text-box">
						<view class="yuedu-tc-text">
							<rich-text :nodes="gonggao.made_illustrate"></rich-text>
						</view>
					</view>
					<view class="tc-btn-box">
						<view class="mshi-btn active">已阅读上述订餐说明</view>
						<button class="qued-btn" @click="queding">确定</button>
					</view>
				</view>
			</view>
			<view class="tc-bg" v-if="guige">
				<view class="tit">{{food.title}}</view>
				<view
					style="width: 15px;height: 15px;text-align: center;line-height: 15px;font-size: 30px;position: absolute;top: 10px;right: 10px;transform:rotate(45deg);"
					@click="guan">+</view>
				<view style="margin-top: 40rpx;margin-bottom: 40rpx;">
					<view :class="foodIndex == index?'guige xuan':'guige'" @click="xuanGuige(index)"
						v-for="(item, index) in food.attrs" :key="index">{{item.name}}</view>
				</view>
				<view class="qian">价格 <span
						style="color:#F7640C;margin-left: 20rpx;">{{food.attrs[foodIndex].discount_price}}</span></view>
				<view class="but" @click="xuangou()">立即选购</view>
			</view>
		</view>
		<!-- 购物车 -->
		<view class="pop-box-bg" v-if="bannerShow">
			<view class="pop-box">
				<view class="toucan-bt">
					<text class="toucan-bt-h4">购物车</text>
					<text class="toucan-bt-span" @click="qingkong">清空菜单</text>
					<text class="toucan-bt-span bot-btn2" @click="zhifu" style="margin:0;margin-left:30rpx">去支付</text>
					<button @tap="closeBanner" class="gb-btn">×</button>
				</view>
				<view class="toucan-box" v-if="quandan">
					<view class="tc-main-box" v-if="deibox">
						<view class="tc-main-bt">
							<text class="tc-main-h4">当前定制菜</text>
							<view class="anbtn-box">
								<button class="bj-btn" @tap="bianjibtn">编辑</button>
								<button class="sanc-btn" @tap="deibtn('当前')">删除</button>
							</view>
						</view>
						<view class="tc-main-list zhucai">
							<view class="tc-main-list-h4">主菜</view>
							<view class="tc-main-list-box" v-for="(cai,z) in dingzData.goods" :key='z'>
								<view class="tc-main-list-box-tx">
									<image :src="cai.cover"></image>
								</view>
								<view class="tc-main-list-box-text">
									<view class="caipin-text">{{cai.title}}，{{cai.attr_name}}</view>
									<view class="caipin-jg">￥{{cai.discount_price}}</view>
								</view>
								<button class="qx-btn" v-if="caidanlist" @click="shanchu(z,'goods')"></button>
							</view>
							<view class="tc-main-list fangshi" v-if="dingzData.cooking != ''">
								<view class="tc-main-list-h4">烹饪方式</view>
								<view class="tc-main-list-box">
									<view class="tc-main-list-box-tx">
										<image :src="dingzData.cooking.pic"></image>
									</view>
									<view class="tc-main-list-box-text">
										<view class="caipin-text">{{dingzData.cooking.name}}</view>
										<view class="caipin-jg">￥{{dingzData.cooking.price}}</view>
									</view>
									<!-- <button class="qx-btn" v-if="caidanlist" @click="shanchu(z,'cooking')">×</button> -->
								</view>
							</view>
							<view class="tc-main-list tiaoliao" v-if="dingzData.seasoning.length != 0">
								<view class="tc-main-list-h4">调料</view>
								<view class="tc-main-list-box" v-for="(tiao,t) in dingzData.seasoning" :key='t'>
									<view class="tc-main-list-box-tx">
										<image :src="tiao.pic"></image>
									</view>
									<view class="tc-main-list-box-text">
										<view class="caipin-text">{{tiao.name}}</view>
									</view>
									<!-- <button class="qx-btn" v-if="caidanlist" @click="shanchu(z,'seasoning')">×</button> -->
								</view>
							</view>
							<view class="tc-main-list peiliao" v-if="dingzData.collocation.length != 0">
								<view class="tc-main-list-h4">配料</view>
								<view class="tc-main-list-box" v-for="(pei,p) in dingzData.collocation" :key='p'>
									<view class="tc-main-list-box-tx">
										<image :src="pei.pic"></image>
									</view>
									<view class="tc-main-list-box-text">
										<view class="caipin-text">{{pei.name}}</view>
									</view>
									<!-- <button class="qx-btn" v-if="caidanlist" @click="shanchu(z,'collocation')">×</button> -->
								</view>
							</view>
						</view>
					</view>
					<view class="tc-main-box" v-if="deibox" v-for="(gwc,i) in GWClist" :key='i'>
						<view class="tc-main-bt">
							<text class="tc-main-h4">第{{i+1}}道菜</text>
							<view class="anbtn-box">
								<!-- <button class="bj-btn" @tap="bianjibtn">编辑</button> -->
								<button class="sanc-btn" @tap="deibtn(gwc.id)">删除</button>
							</view>
						</view>
						<view class="tc-main-list zhucai">
							<view class="tc-main-list-h4">主菜</view>
							<view class="tc-main-list-box" v-for="(cai,z) in gwc.detail.goods" :key='z'>
								<view class="tc-main-list-box-tx">
									<image :src="cai.cover"></image>
								</view>
								<view class="tc-main-list-box-text">
									<view class="caipin-text">{{cai.title}}，{{cai.attr_name}}</view>
									<view class="caipin-jg">￥{{cai.discount_price}}</view>
								</view>
								<!-- <button class="qx-btn" v-if="caidanlist">×</button> -->
							</view>
						</view>
						<view class="tc-main-list fangshi">
							<view class="tc-main-list-h4">烹饪方式</view>
							<view class="tc-main-list-box">
								<view class="tc-main-list-box-tx">
									<image :src="gwc.detail.cooking.pic"></image>
								</view>
								<view class="tc-main-list-box-text">
									<view class="caipin-text">{{gwc.detail.cooking.name}}</view>
									<view class="caipin-jg">￥{{gwc.detail.cooking.price}}</view>
								</view>
								<!-- <button class="qx-btn" v-if="caidanlist">×</button> -->
							</view>
						</view>
						<view class="tc-main-list tiaoliao">
							<view class="tc-main-list-h4">调料</view>
							<view class="tc-main-list-box" v-for="(tiao,t) in gwc.detail.seasoning" :key='t'>
								<view class="tc-main-list-box-tx">
									<image :src="tiao.pic"></image>
								</view>
								<view class="tc-main-list-box-text">
									<view class="caipin-text">{{tiao.name}}</view>
								</view>
								<!-- <button class="qx-btn" v-if="caidanlist">×</button> -->
							</view>
						</view>
						<view class="tc-main-list peiliao">
							<view class="tc-main-list-h4">配料</view>
							<view class="tc-main-list-box" v-for="(pei,p) in gwc.detail.collocation" :key='p'>
								<view class="tc-main-list-box-tx">
									<image :src="pei.pic"></image>
								</view>
								<view class="tc-main-list-box-text">
									<view class="caipin-text">{{pei.name}}</view>
								</view>
								<!-- <button class="qx-btn" v-if="caidanlist">×</button> -->
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 弹窗背景 -->
		<view class="tc-fbg" v-if="bannerShow"></view>
	</view>
</template>
<script>
	import Vue from 'vue'
	export default {
		data() {
			return {
				isActive: false,
				hasError: false,
				GWClist: [],
				dingzData: '',
				zongqian: 0,
				youhui: 0,
				num: 0,
				gonggao: uni.getStorageSync("jyfw"),
				shangzong: 0,
				shangyou: 0,
				xiuxi:false,
				yijilei:[],
				yijileiIndex:0,
				childrenIndex:-1,

				gwc: '',
				bannerShow: false,
				caidanlist: false,
				deibox: true,
				quandan: true,
				sousuo: '',
				zbc: true,
				msg:'',
				show: false,
				guige: false,
				food: '',
				foodIndex: 0,
				goods1: {
					children:[],
					foods:[]
				},
				goods2: [],
				xuan2: 0,
				zhucai: [],
				page: 1,
				psize: 10,
				keyword: '',
				goods: [],
				windows_height: 0, //屏幕高度
				foodSTop: 0, //右侧的滑动值
				currentIndex: 0,
				last: 0,
				right_height: [], //右侧每个内容的高度集合
				select_index: 0,
				left_height: 0, //左侧总高度
				left_scroll: 0, //左侧滑动值
				catrgoryList: [],
				timeout: null
			}
		},

		onLoad(data) {
			// if (uni.getStorageSync("user").nickname == null) {
      //   wx.reLaunch({
      //     url: "/pages/my/login"
      //   });
      // }
			this.windows_height = Number(uni.getSystemInfoSync().windowHeight) - 298;
			setTimeout(() => {
				this.getHeightList();
			}, 1000)
			var than = this;
			uni.request({
				url: getApp().globalData.http + "/config/orderStatus",
				data: {},
				method: "post",
				header: {
					"content-type": "application/x-www-form-urlencoded",
					token: uni.getStorageSync("token")
				},
				success: res => {
					if (res.data.code == 1) {
						if (getApp().globalData.kaiguan) {
							than.zbc = true
							than.show = true
						}else{
							than.zbc = false
							than.show = false
						}
						than.dingzData = getApp().globalData.dingzhicai.detail
						than.getList1()
						than.getGWC()
					} else {
						than.msg = res.data.msg
						than.zbc = true
						than.show = false
						than.xiuxi = true
					}
				}
			});
		},
		onShow(){
			this.getGWC()
			this.dingzData = getApp().globalData.dingzhicai.detail
		},
		// 弹窗
		onBackPress() {
			if (this.bannerShow) {
				this.bannerShow = false;
				return true;
			}
		},
		methods: {
			getGWC() { //获取购物车列表                       
				var than = this
				uni.request({
					url: getApp().globalData.http + "/shoppingCart/getList",
					data: {},
					method: "post",
					header: {
						"content-type": "application/x-www-form-urlencoded",
						token: uni.getStorageSync("token")
					},
					success: res => {
						if (res.data.code == 1) {
							than.GWClist = res.data.data
							than.num = than.GWClist.length
							if (getApp().globalData.dingzhicai.detail.goods.length != 0) {
								than.num = this.num + 1
							}
							if (than.GWClist.length != 0) { //不等于0，购物车有菜
								than.GWClist.forEach(k => {
									if (!k.detail.goods) { //定制菜页面
										var than = this
										uni.request({
											url: getApp().globalData.http +
												"/shoppingCart/clear",
											data: {},
											method: "post",
											header: {
												"content-type": "application/x-www-form-urlencoded",
												token: uni.getStorageSync("token")
											},
											success: res => {
												than.GWClist = []
												than.num = than.GWClist.length
											}
										})
									}
								});
							}

							var zongqian = 0
							var yuanjia = 0
							var pengr = 0
							than.GWClist.forEach(e => {
								e.detail.goods.forEach(i => {
									zongqian += Number(i.discount_price);
									yuanjia += Number(i.market_price)
								});
								pengr += Number(e.detail.cooking.price)
							});
							if (getApp().globalData.dingzhicai.detail.goods.length != 0) {
								getApp().globalData.dingzhicai.detail.goods.forEach(k => {
									zongqian += Number(k.discount_price);
									yuanjia += Number(k.market_price)
								});
							}
							than.youhui = (Number(yuanjia) - Number(zongqian)).toFixed(2)
							if (getApp().globalData.dingzhicai.detail.cooking != '') {
								zongqian += Number(getApp().globalData.dingzhicai.detail.cooking.price)
							}
							than.zongqian = (zongqian + pengr).toFixed(2)


						} else {
							wx.showToast({
								title: res.data.msg,
								icon: "none",
								duration: 2000
							});
						}
					}
				});
			},

			shanchu(index) {
				this.zongqian = (this.zongqian - getApp().globalData.dingzhicai.detail.goods[index].discount_price)
					.toFixed(2)
				var chajia = getApp().globalData.dingzhicai.detail.goods[index].market_price - getApp().globalData
					.dingzhicai.detail.goods[index].discount_price
				this.youhui = (this.youhui - chajia).toFixed(2)
				getApp().globalData.dingzhicai.detail.goods.splice(index, 1)
				if (getApp().globalData.dingzhicai.detail.goods.length == 0) {
					this.num = this.num - 1
				}
				this.dingzData = getApp().globalData.dingzhicai.detail
			},


			search(){
				wx.navigateTo({
					url: '/pages/my/search?keyword='+this.keyword
				})
			},

			/* 购物车开关*/
			closeBanner: function() {
				this.bannerShow = false;
			},
			showBanner: function() {
				this.bannerShow = true;
			},
			/* 编辑开关*/
			bianjibtn: function() {
				this.caidanlist = true;
			},
			/* 删除开关*/
			deibtn: function(id) {
				if (id == '当前') {
					getApp().globalData.dingzhicai = {
						type: 2,
						goods_id: 0,
						num: 1,
						remark: '',
						detail: {
							goods: [], //主菜
							cooking: [], //烹饪方式
							collocation: [], //配菜
							seasoning: [] //调料
						}
					}
					this.dingzData = getApp().globalData.dingzhicai.detail
					this.getGWC()
				} else {
					var than = this;
					uni.request({
						url: getApp().globalData.http + "/shoppingCart/remove",
						data: {
							id: id,
							num: 1
						},
						method: "post",
						header: {
							"content-type": "application/x-www-form-urlencoded",
							token: uni.getStorageSync("token")
						},
						success: res => {
							if (res.data.code == 1) {
								than.getGWC()
							} else {
								wx.showToast({
									title: res.data.msg,
									icon: "none",
									duration: 2000
								});
							}
						}
					});
				}
				// this.deibox=false;
			},
			/* 清空开关*/
			qingkong: function() {
				var than = this;
				uni.request({
					url: getApp().globalData.http + "/shoppingCart/clear",
					data: {},
					method: "post",
					header: {
						"content-type": "application/x-www-form-urlencoded",
						token: uni.getStorageSync("token")
					},
					success: res => {
						if (res.data.code == 1) {
							getApp().globalData.dingzhicai.detail={
																goods:[],//主菜
																cooking:'',//烹饪方式
																collocation:[],//配菜
																seasoning:[]//调料
															}
							this.dingzData = getApp().globalData.dingzhicai.detail
							than.getGWC()
						} else {
							wx.showToast({
								title: res.data.msg,
								icon: "none",
								duration: 2000
							});
						}
					}
				});
				// this.quandan = false;
			},
			getList1() { //获取一级分类
				var than = this;
				uni.request({
					url: getApp().globalData.http + "/made/getClass",
					data: {
						pid: 0
					},
					method: "post",
					header: {
						"content-type": "application/x-www-form-urlencoded",
						token: uni.getStorageSync("token")
					},
					success: res => {
						if (res.data.code == 1) {
							res.data.data.forEach((e) => {
								than.yijilei.push({
									name: e.title,
									id: e.id,
									index: 0,
								})
							})
							this.getList2(res.data.data[0].id)


							// res.data.data.forEach((e, num) => {
							// 	than.goods1.push({
							// 		name: e.title,
							// 		id: e.id,
							// 		index: 0,
							// 		children: [],
							// 		foods: []
							// 	})
							// 	this.getList2(e.id, num)
							// });
						} else {
							wx.showToast({
								title: res.data.msg,
								icon: "none",
								duration: 2000
							});
						}
					}
				});
			},
			getList2(id) { //获取二级分类
				var than = this;
				uni.request({
					url: getApp().globalData.http + "/made/getClass",
					data: {
						pid: id
					},
					method: "post",
					header: {
						"content-type": "application/x-www-form-urlencoded",
						token: uni.getStorageSync("token")
					},
					success: res => {
						if (res.data.code == 1) {
							than.goods1.children = res.data.data   //添加2级
							res.data.data.forEach((e,index) => {
								than.getList3(id, e.id,e.title,index)
							});
							// var sort = 0;
							// res.data.data.forEach(e => {
							// 	this.getList3(id, e.id, num, e.title,sort)
							// 	sort++
							// });

						} else {
							wx.showToast({
								title: res.data.msg,
								icon: "none",
								duration: 2000
							});
						}
					}
				});
			},
			getList3(id1, id2, name,index) { //获取主菜
				var than = this;
				uni.request({
					url: getApp().globalData.http + "/made/getList",
					data: {
						top_class_id: id1,
						sub_class_id: id2,
						keyword: '',
						page: 1,
						psize: 9999
					},
					method: "post",
					header: {
						"content-type": "application/x-www-form-urlencoded",
						token: uni.getStorageSync("token")
					},
					success: res => {
						if (res.data.code == 1) {
							Vue.set(than.goods1.foods,index,{
								name: name,
								list: res.data.data.data
							})
							than.goods2 = JSON.parse(JSON.stringify(than.goods1))
							// than.goods1.foods[index] = {
							// 	name: name,
							// 	list: res.data.data.data
							// }
							

							
							// than.goods1[num].foods[sort]={
							// 	name: name,
							// 	list: res.data.data.data
							// }


							// than.goods1[num].foods.push({
							// 	name: name,
							// 	sort: sort,
							// 	list: res.data.data.data
							// })
						} else {
							wx.showToast({
								title: res.data.msg,
								icon: "none",
								duration: 2000
							});
						}
					}
				});
			},

			childrenCk(index) {
				console.log(this.goods2.foods[index]);
				
				if (index == -1) {
					this.goods1.foods = this.goods2.foods
				}else{
					this.goods1.foods = [this.goods2.foods[index]]
				}
				console.log(this.goods1.foods);
				
				this.childrenIndex = index
				

			},
			guigeCk(data) {
				this.food = data
				this.zbc = true
				this.guige = true
			},
			xuanGuige(index) {
				this.foodIndex = index
			},
			queding() {
				this.zbc = false
				this.show = false
				getApp().globalData.kaiguan = false
			},
			xuangou() {
				var data = {
					id: this.food.id,
					title: this.food.title,
					cover: this.food.cover,
					attr_name: this.food.attrs[this.foodIndex].name,
					attr_id: this.food.attrs[this.foodIndex].id,
					market_price: this.food.attrs[this.foodIndex].market_price,
					discount_price: this.food.attrs[this.foodIndex].discount_price,
				}
				this.zongqian = (Number(this.zongqian) + Number(data.discount_price)).toFixed(2)
				this.youhui = (Number(this.youhui) + (Number(data.market_price) - Number(data.discount_price))).toFixed(2)
				getApp().globalData.dingzhicai.detail.goods.push(data)
				if (getApp().globalData.dingzhicai.detail.goods.length == 1) {
					this.num = this.GWClist.length + 1
				}
				this.dingzData = getApp().globalData.dingzhicai.detail
				wx.showToast({
					title: '添加主菜成功',
					icon: "success",
					duration: 2000
				});
				this.zbc = false
				this.guige = false
			},
			guan() {
				this.zbc = false
				this.guige = false
			},
			//下一步
			xybck() {
				if (getApp().globalData.dingzhicai.detail.goods.length == 0) {
					wx.showToast({
						title: '请添加主菜！',
						icon: "none",
						duration: 2000
					});
					return
				}
				wx.navigateTo({
					url: '/pages/my/custom-list2?zong=' + this.zongqian + '&you=' + this.youhui
				})
			},
			zhifu(){
				if (getApp().globalData.dingzhicai.detail.goods.length != 0) {
					wx.showToast({
						title: '请完成菜品的点餐步骤后支付！',
						icon: "none",
						duration: 2000
					});
					return
				}
				wx.navigateTo({
					url:'/pages/my/distribution'
				})
			},
			// 点击侧边栏
			select(index,id) {
				this.yijileiIndex = index;
				this.childrenIndex = -1
				this.goods1.foods = []
				this.getList2(id)
			},

			// 设置点击侧边栏右边滚动的高度
			setScrollH: function(index) {
				var that = this;
				let height = 0;
				var query = uni.createSelectorQuery();
				let foods = query.selectAll('.foods');

				this.$nextTick(function() {
					foods.fields({
						size: true
					}, data => {
						if (index == 0) {
							that.foodSTop = 0;
						}
						for (let i = 0; i < index; i++) {
							height += parseInt(data[i].height);
							that.foodSTop = height;
						}

					}).exec();
				})

			},

			addCart: function(item) {
				var data = {
					id: item.id,
					title: item.title,
					cover: item.cover,
					attr_name: item.attrs[0].name,
					attr_id: item.attrs[0].id,
					market_price: item.attrs[0].market_price,
					discount_price: item.attrs[0].discount_price,
				}
				this.zongqian = (Number(this.zongqian) + Number(data.discount_price)).toFixed(2)
				this.youhui = (Number(this.youhui) + (Number(data.market_price) - Number(data.discount_price)))
					.toFixed(2)
				getApp().globalData.dingzhicai.detail.goods.push(data)
				if (getApp().globalData.dingzhicai.detail.goods.length == 1) {
					this.num += 1
				}
				this.dingzData = getApp().globalData.dingzhicai.detail
				wx.showToast({
					title: '添加主菜成功',
					icon: "success",
					duration: 2000
				});
			},
			decreaseCart(item) {
				if (item.count) {
					item.count--
					this.goods.forEach((good) => {
						good.foods.forEach((food) => {
							if (item.name == food.name)
								food.count = item.count
						})
					})
				}
			},
			// 清空购物车
			delAll() {
				this.goods.forEach((good) => {
					good.foods.forEach((food) => {
						if (food.count) {
							food.count = 0
						}
					})
				})
			},
			details(id){
				wx.navigateTo({
      	  url: '/pages/my/custom-info?id=' + id
      	});
			},

			getHeightList() {
				let _this = this;
				let selectorQuery = uni.createSelectorQuery().in(this);
				selectorQuery.select('.left-content').boundingClientRect(function(rects) {
					_this.left_height = rects.height;
				});
				selectorQuery.selectAll('.foods').boundingClientRect(function(rects) {
					_this.right_height = rects.map((item) => item.top);
				}).exec();
			},
			myscroll(e) {
				//引入节流	
				let right_content_height = e.detail.scrollHeight - this.windows_height;
				if (right_content_height == e.detail.scrollTop) {
					return;
				}
				let scroll_top = e.detail.scrollTop + 260; //110是banner图的高度
				//判断当前的scrollTop在哪个区间内;
				let now = +new Date();
				if (scroll_top > 260) {
					this.isActive=true;
					this.hasError=true;
				}else{
					this.isActive=false;
					this.hasError=false
				}
			}
		}
	}
</script>
<style scoped>
	.custom-list-p{overflow: hidden; margin: 0 auto; border-bottom: 5px solid #fff; width: 100%; background: #e15e07; }
	.custom-list-p text{ overflow: hidden; margin: 0 auto;  display: table; height: 35px; line-height: 35px; font-size: 32upx; color: #fff; text-align: center; }
	.zbc {
		position: fixed;
		width: 100%;
		top: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.3);
		z-index: 999;
	}
	.foods-box view{overflow: hidden;}
	.xiuxi{
		width: 80%;
    background-color: #fff;
    text-align: center;
    margin-left: 10%;
    margin-top: 35%;
    padding: 15px 0;
    border-radius: 5px;
	}

	.tc-bg {
		position: absolute;
		width: 80%;
		height: auto;
		margin-left: 10%;
		margin-top: 40%;
		background-color: #fff;
		border-radius: 20rpx;
		padding-bottom: 40rpx;
		z-index: 999;
	}

	.tc-bg .tit {
		margin-top: 20rpx;
		margin-left: 30rpx;
	}

	.tc-bg .guige {
		display: inline-block;
		padding: 15rpx;
		margin-bottom: 20rpx;
		margin-left: 30rpx;
		border-radius: 10rpx;
		font-size: 26rpx;
		border: 1rpx solid #E3E0E1;
	}

	.tc-bg .xuan {
		border: 1rpx solid #1AC56D;
		background-color: #ECFEF6;
	}

	.tc-bg .qian {
		display: inline-block;
		margin-top: 20rpx;
		margin-left: 30rpx;
		font-size: 34rpx;
	}

	.tc-bg .but {
		position: absolute;
		right: 50rpx;
		bottom: 30rpx;
		display: inline-block;
		padding: 16rpx;
		background-color: #09C15F;
		color: #fff;
		font-size: 30rpx;
		border-radius: 20rpx;
	}

	.current {
		position: relative;
		z-index: 0;
		background-color: #fff;
		color: #00A0DC;
		border-left: 5px solid #00A0DC;
	}

	.menu-wrapper {
		text-align: center;
		width: 25%;
		display: flex;
		flex-direction: column;
		background: #f3f5f7;

	}

	.menu-item {
		width: 100%;
		display: flex;
		font-size: 24upx;
		align-items: center;
		justify-content: center;
		height: 40px;
	}

	.allcount {
		position: absolute;
		right: 6px;
		top: 8px;
		display: inline-block;
		padding: 0 4px;
		font-size: 12px;
		line-height: 16px;
		font-weight: 400;
		border-radius: 50%;
		background-color: #f01414;
		color: #ffffff;
	}

	.foods-wrapper {
		width: 75%;
	}

	.food,
	.food-btm,
	.main-box {
		display: flex;
		flex-direction: row;
	}

	.food-info {
		margin-left: 10px;
		margin-right: 16px;
		display: flex;
		flex-direction: column;
		flex: 2;
	}

	.food-btm {
		justify-content: space-between;
	}

	.food-price {
		color: #f01414;
		font-size: 16px;
	}
</style>
